<template>
  <div>
    <!--    <el-button type="primary" @click="delrouterall()">click</el-button>-->


    <div style="margin: 10px 0">
      <div style="float: left; margin-bottom: 15px">
        <el-cascader
            style="margin-left: 10px; width: 255px"
            placeholder="请选择单位"
            ref="dwref"
            v-model="dwid"
            @change=""
            :options="dwoptions"
            :props="{ expandTrigger: 'hover', checkStrictly: true, label: 'dwname', value:'id', emitPath: false }"
            clearable>
        </el-cascader>
        <el-input style="width: 200px; margin: 0 10px 0 10px" placeholder="请输入井号" suffix-icon="el-icon-search"
                  v-model="jh"/>
        <el-button type="primary" @click="search" icon="el-icon-search">搜索</el-button>
      </div>
    </div>


    <el-table ref="table" @selection-change="handleSelectionChange" :data="tableData"
              style="margin: 10px; width: 1600px" border stripe>
<!--      <el-table-column width="50" type="selection">-->
<!--      </el-table-column>-->
      <el-table-column type="index" label="序号" width="60">
      </el-table-column>
      <el-table-column prop="id" label="ID" width="60" v-if="false">
      </el-table-column>
      <el-table-column prop="jh" label="井号" width="100">
      </el-table-column>
      <el-table-column prop="xx" label="液位下降下限" width="150">
        <template slot-scope="scope">
          <el-input v-model="scope.row.xx"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="sx" label="液位下降上限" width="150">
        <template slot-scope="scope">
          <el-input v-model="scope.row.sx"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="sjkd" label="时间跨度" width="150">
        <template slot-scope="scope">
          <el-input v-model="scope.row.sjkd" type="number"></el-input>
        </template>
      </el-table-column>

      <el-table-column prop="userObj.username" label="设置人" width="150">
<!--        <template slot-scope="scope">-->
<!--          <el-input v-model="scope.row.szr" disabled></el-input>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column prop="szsj" label="设置时间" width="200">
      </el-table-column>

      <el-table-column prop="#" label="操作">
        <template slot-scope="scope">
          <el-button size="small" type="primary" @click="handleSave(scope.row)">保存<i
              class="el-icon-edit"></i></el-button>
          <el-popconfirm
              style="margin: 0 10px"
              confirm-button-text='确定'
              cancel-button-text='取消'
              icon="el-icon-info"
              icon-color="red"
              title="恢复默认值吗？"
              @confirm="handleRestore(scope.row.id)"
          >
            <el-button size="small" type="success" slot="reference">恢复默认 <i class="el-icon-remove-outline"></i>
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

<!--    <div class="block" style="padding: 5px">-->
<!--      <el-pagination-->

<!--          @size-change="handleSizeChange"-->
<!--          @current-change="handleCurrentChange"-->
<!--          :current-page="currentPage"-->
<!--          :page-sizes="[10, 20, 50, 100,500,1000]"-->
<!--          :page-size="pageSize"-->
<!--          layout="total, sizes, prev, pager, next, jumper"-->
<!--          :total="total">-->
<!--      </el-pagination>-->
<!--    </div>-->

  </div>

</template>
<script>
import service from "@/utils/request";
import ElementUI from "element-ui";

import VueRouter from 'vue-router'
import HomeView from "@/views/HomeView.vue";


export default {
  created() {
    service.get('/dw/getAll', {}).then(
        response => {
          if (response.data.code == 20000) {
            this.dwoptions = response.data.data
          }
        }
    )
    this.load();
  },
  data() {
    return {
      dwoptions: [],
      dwid: null,
      dwval: [],
      jh: '',
      gx: null,
      gxArr: [],
      tableData: [],
      selectedRows: [], // 用来存储选中行的数据
      pageSize: 10,
      total: 100,
      currentPage: 1,
      dialogFormVisible: false,
      editFormVisible: false,

      formLabelWidth: '150px'
    }
  },
  methods: {
    test() {
      service.get('/dj/test', {}).then(
          response => {
            if (response.data.code == 20000) {

              this.$message.success(response.data.message)
            }
          }
      )

    },

    load() {
      service.get('/jygywyz/getBydwJh', {
        params: {
          pagesize: this.pageSize,
          pagenum: this.currentPage,
          jh: this.jh,
          dwid: this.dwid,  //因为是拷贝的tj。vue，所以这个参数是多余的，置为空
          // gx: null //因为是拷贝的tj。vue，所以这个参数是多余的，置为空
        }
      }).then(response => {
            if (response.data.code == 20000) {
              // this.tableData = response.data.data.records;
              // this.total = response.data.data.total;
              // this.currentPage = response.data.data.current;
              // this.pageSize = response.data.data.size;
              // while(this.tableData.length>0){
              //   this.tableData.pop()
              // }
              this.tableData = []
              for(var i=0;i<response.data.data.length;i++){
                this.tableData.push(response.data.data[i])
              }
              // this.tableData = response.data.data
            }
          },
          error => {
            ElementUI.Message({
              message: error.message,
              type: 'error'
            })
          }
      );

    },



    handleSelectionChange(selection) {
      // console.log(selection)
      // this.selectedRows = selection.map(row => row._row);
      this.selectedRows = selection
      // console.log(this.selectedRows)
    },


    handleSizeChange(val) {
      this.pageSize = val
      this.load()
    },

    handleCurrentChange(val) {
      this.currentPage = val
      this.load()
    },

    handleSave(row) {
      // console.log(this.form)
      // this.$refs.saveform.validate(valid => {
      //   if (!valid) {
      //     return false
      //   }
      //   let saveform = {...this.form}

        // saveform.dw = this.form.dw == null ? null : this.form.dw[this.form.dw.length - 1]
      service.post('/jygywyz/edit', row).then(response => {
        if (response.data.code == 20000) {
          this.$message.success('success!');
          // this.dialogFormVisible = false
          this.load()
        } else {
          this.$message.error("error")
          this.dialogFormVisible = false
        }
      })
      // })

    },


    search() {
      // this.currentPage = 1
      this.load()
    },
    handleDelBatch() {
      service.post('/yjxx/delbatch', this.selectedRows).then(response => {
        if (response.data.code == 20000) {
          this.$message.success('删除成功!');
          this.load()
        } else {
          this.$message.error("error")
        }
      })
    },

  }
}
</script>

<style scoped>

</style>
